const reqIP = "https://1c92-111-1-51-127.ngrok-free.app";

const headers = {
  // "Access-Control-Allow-Headers": "x-requested-with,content-type",
  "Content-Type": "application/x-www-form-urlencoded",
  "Access-Control-Allow-Origin": "*",
  "Access-Control-Allow-Methods": "POST,GET",
  "ngrok-skip-browser-warning": "69420",
};

//axios封装post请求
export const axiosPostRequst = function (url, data) {
  let result = axios({
    method: "post",
    baseURL: reqIP,
    url: url,
    data: data,
    transformRequest: [
      function (data) {
        let ret = "";
        for (let i in data) {
          ret +=
            encodeURIComponent(i) + "=" + encodeURIComponent(data[i]) + "&";
        }
        return ret;
      },
    ],
    // withCredentials: true,
    headers,
  })
    .then((resp) => {
      console.log("axiosPostRequst resp", resp);
      return resp.data;
    })
    .catch((error) => {
      return "exception=" + error;
    });
  return result;
};

//get请求
export const axiosGetRequst = function (url) {
  var result = axios({
    method: "get",
    baseURL: reqIP,
    url: url,
    headers,
  })
    .then(function (resp) {
      console.log("axiosGetRequst resp", resp);
      return resp.data;
    })
    .catch(function (error) {
      return "exception=" + error;
    });
  return result;
};
